<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\ActiveForm;
use app\modules\search\models\SearchSenior;
use app\modules\clinical\models\Patient;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '高级搜索';
$this->registerJsFile('@web/js/search.js?v=1', ['depends' => 'app\assets\AppAsset']);
?>
<style type="text/css">
    .search-div > div > table {width: 1400px !important;}
    .search-box {width: auto; display: inline-block;}
    .dropdown-list {position: absolute; width: 80%; background-color: #fff; border: 1px solid #337ab7; padding: 8px; display: none;}
    .dropdown-list a {border-radius: 0; font-size: 12px; margin: 4px;}
    .dropdown-list .unselected {background-color: #ececec; color: #000;}
    .dropdown-list .selected {background-color: #337ab7; color: #fff;}
    .dropdown-toggle span {margin-right: 3px;}
    .label i {cursor: pointer;}
    table {width: 100%;}
    table tr {height: 40px;}
</style>

<?php $form = ActiveForm::begin(['method' => 'get', 'action' => '/search/search/senior', 'id' => 'search-form']); ?>
<p>
    <?= Html::a('清空搜索', ['/search/search/senior'], ['class' => 'btn btn-primary']) ?>
    <?= Html::button('搜索', ['class' => 'btn btn-success', 'type' => 'submit']) ?>
</p>

<table>
  <tr>
    <td width="80px">药物剂量：</td>
    <td>
	    <?= $form->field($searchModel, 'med_name', ['options' => ['class' => 'search-box']])->dropDownList($med_info)->label(false)->error(false) ?>

	    <?= $form->field($searchModel, 'med_rel', ['options' => ['class' => 'search-box']])->dropDownList($med_rel)->label(false)->error(false) ?>

	    <?= $form->field($searchModel, 'med_ammout', ['options' => ['class' => 'search-box']])->textInput()->label(false)->error(false) ?>
	</td>
  </tr>
  <tr>
    <td>发病年龄：</td>
  	<td>
	    <?= $form->field($searchModel, 'age_rel', ['options' => ['class' => 'search-box']])->dropDownList($age_rel)->label(false)->error(false) ?>

	    <?= $form->field($searchModel, 'pt_age', ['options' => ['class' => 'search-box']])->textInput()->label(false)->error(false) ?>
    </td>
  </tr>
  <tr>
    <td>DBS：</td>
  	<td>
    	<?= $form->field($searchModel, 'dbs', ['options' => ['class' => 'search-box']])->radioList(['1' => '选择作为筛选条件'])->label(false)->error(false) ?>
    </td>
  </tr>
  <tr>
    <td>既往史：</td>
    <td>
    	<span class="form-control pt_history dropdown-toggle"></span>
			<?= $form->field($searchModel, 'pt_history', ['options' => ['class' => 'hidden']])->hiddenInput()->label(false) ?>
			<div class="dropdown-list">
        <?php foreach (Patient::getParams('history') as $key => $pt_history):?>
            <span>
                <a href="javascript:void(0);" class="btn unselected" data-id="<?= $key ?>"><?= $pt_history ?></a>
            </span>
        <?php endforeach;?>
        </div>
		</td>
  </tr>
  <tr>
    <td>标签：</td>
    <td>
        <span class="form-control pt_label dropdown-toggle"></span>
  		<?= $form->field($searchModel, 'pt_label', ['options' => ['class' => 'hidden']])->hiddenInput()->label(false) ?>
  		<div class="dropdown-list">
        <?php foreach ($labels as $key => $label):?>
            <span>
                <a href="javascript:void(0);" class="btn unselected" data-id="<?= $key ?>"><?= $label ?></a>
            </span>
        <?php endforeach;?>
        </div>
		</td>
  </tr>
</table>
<?php ActiveForm::end(); ?>

<div class="search-div">
<?= GridView::widget([
	'dataProvider' => $dataProvider,
	'columns' => [

		[
		    'value' => function($data) {
		        return Html::a('<i class="fa fa-paper-plane"></i>', '/search/search/enter/?id='.$data->pk_id.'&name='.$data->pt_name.'&dna='.$data->dna_id);
		    },
		    'format' => 'html',
		],
		'pt_id',
		'pt_name',
		'pt_birth',
		'pt_age',
		[
			'attribute' => 'pt_history',
			'value' => function($model) {
				return SearchSenior::getHistory($model->pt_history);
			}
		],
		[
			'attribute' => 'pt_label',
			'value' => function($model) {
				return Patient::getLabel($model->pt_label);
			}
		],
		'dbs_id',
		'dbs_time',
		'med_id',

		],
	]); ?>
</div>
